package myJs.common

import myJs.myPkg.reactHookForm._
import slinky.core.FunctionalComponent
import slinky.core.annotations.react
import slinky.core.facade.ReactElement
import slinky.web.html._

import scala.scalajs.js
import myJs.Implicits._

/**
 * Created by yz on 3/11/2020
 */
@react object FormGroupInlineCp {

  case class Props(
                    useForm: UseFormRT,
                    names: List[String],
                    children: ReactElement*
                  )

  val component = FunctionalComponent[Props] { props =>

    val hasErrorCls = if (props.names.exists(props.useForm.formState.errors.deepDefinedAt(_))) "has-error" else ""

    div(className := s"form-group ${hasErrorCls}",
      props.children
    )


  }

}



